package pe.gob.mef.snip.preinversion.controller;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import pe.gob.mef.snip.preinversion.domain.MetaBanco;
import pe.gob.mef.snip.preinversion.service.MetaBancoService;

@Controller
public class MetaBancoController {

	@Autowired
	private MetaBancoService metaBancoService;
	
	private MetaBanco metaBanco;

	
	@RequestMapping("/metaBancoListar")
	public ModelAndView listar(HttpServletRequest request, HttpServletResponse response) {
		
		metaBanco = new MetaBanco();
		metaBancoService.listar(metaBanco);
		
		return new ModelAndView("metaBancoMantenimiento","metaBanco",metaBanco.getResultList());
	}
	
	@RequestMapping("/metaBancoRegistrar")
	public ModelAndView registrar(HttpServletRequest request, HttpServletResponse response) {		
		metaBanco = new MetaBanco();
		metaBancoService.listar(metaBanco);
		return new ModelAndView("metaBancoRegistrar","metaBanco",metaBanco.getResultList());
	}
	
	@RequestMapping("/metaBancoSeleccionar")
	public ModelAndView seleccionar(HttpServletRequest request, HttpServletResponse response) {
		
		metaBanco = new MetaBanco();
	
		metaBancoService.obtener(metaBanco);

		return new ModelAndView("metaBancoRegistrar","metaBanco",metaBanco.getResultList());
		
	}
	
	@RequestMapping("/metaBancoGrabar")
	public ModelAndView grabar(HttpServletRequest request, HttpServletResponse response) {
		
		metaBanco = new MetaBanco();
		
		Map<String, Object> metaBancoMap = new HashMap<String, Object>();
		metaBancoMap.put("metaBanco", metaBanco);

		return new ModelAndView("metaBancoRegistrar","metaBancoMap",metaBancoMap);
	}
	
	@RequestMapping("/metaBancoEliminar")
	public ModelAndView eliminar(HttpServletRequest request, HttpServletResponse response) {
		
		metaBanco = new MetaBanco();
		metaBancoService.eliminar(metaBanco);

		metaBancoService.listar(metaBanco);
		
		return new ModelAndView("metaBancoMantenimiento","metaBanco",metaBanco.getResultList());
	}
	
	
}

